/*
 * Settings.java
 *
 * Created on 31 Март 2008 г., 3:11
 */

package dbmsclient;

import java.util.ResourceBundle;

/**
 *
 * @author  makarof
 */
public class DbmsClientSettings extends javax.swing.JDialog {
    
    /** Creates new form Settings */
    public DbmsClientSettings(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        hostTextField.setText(DbmsClientView.HOST_NAME);
        portSpinner.setValue(DbmsClientView.HOST_PORT);
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        portSpinner = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        hostTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getString("title")); // NOI18N
        setName("settings"); // NOI18N
        setResizable(false);

        portSpinner.setValue(1234);

        jLabel1.setFont(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getFont("jLabel2.font")); // NOI18N
        jLabel1.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getString("jLabel1.text")); // NOI18N

        jLabel2.setFont(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getString("jLabel2.text")); // NOI18N

        jLabel3.setFont(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getString("jLabel3.text")); // NOI18N

        jButton1.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getString("jButton1.text")); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText(application.Application.getInstance(dbmsclient.DbmsClientApp.class).getContext().getResourceMap(DbmsClientSettings.class).getString("jButton2.text")); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        hostTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        hostTextField.setText("jTextField1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addContainerGap(260, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel3))
                                .addGap(28, 28, 28)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(hostTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                                    .addComponent(portSpinner, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))))
                        .addGap(26, 26, 26))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(hostTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(portSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
public void reloadComponents(ResourceBundle bundle) {
    jLabel3.setText(bundle.getString("settings"));
    jLabel1.setText(bundle.getString("host"));
    jLabel2.setText(bundle.getString("port"));
    DbmsClientSettings.this.setTitle(bundle.getString("connectSettings"));
    jButton1.setText(bundle.getString("save"));
    jButton2.setText(bundle.getString("cancel"));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    setVisible(false);
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    DbmsClientView.HOST_NAME = hostTextField.getText();
    DbmsClientView.HOST_PORT = Integer.parseInt(portSpinner.getValue().toString());
    setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                DbmsClientSettings dialog = new DbmsClientSettings(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField hostTextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JSpinner portSpinner;
    // End of variables declaration//GEN-END:variables
    
}
